<?php
namespace app\api\command;

use app\api\controller\Base;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class Anonymous extends Command
{
    protected function configure()
    {
        $this->setName('anonymous')->setDescription('finish order Anonymous');
    }

    protected function execute(Input $input, Output $output)
    {
        /* 永不超时 */
        ini_set('max_execution_time', 0);
        $this->doCron();
    }


    public function doCron(){

        $cache = cache('command'.__CLASS__);
        if ($cache){
            echo 'running<br />';return false;
        }else{
            cache('command'.__CLASS__,true,1800);
        }

        $map['status'] = 4;
        $map['update_time'] = ['< time',time()-86400 *3];
        Db::name('order')->where($map)->chunk(1000,function ($items){
            foreach ($items as $k => $v){
                $item = [];
                $item['id'] = $v['order_id'];
                $item['score'] = 5;
                $item['content'] = '系统默认评价';
                $result = Base::orderAnonymous($item);
                if ($result !== true){
                    var_dump($result);
                }
            }
        });

        cache('command'.__CLASS__,null);

    }
}